﻿function main() {
    showLog("抖音(同城评论)");
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var contentArr = viewJson.contentArr;
    AccessibilityEngine.sleepEngine(8000);//等待
	 var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(1000);//等待
	
    if (AccessibilityEngine.checkUpText("同城")==ISTRUE ) {		
        AccessibilityEngine.mockOnClickIdText("com.ss.android.ugc.aweme:id/den", "同城"); //点击同城
    }else{
	     AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dyx");
	}

    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(3000);//等待
    for (var aa=0; aa<30; aa++ ){
        if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
        }
        if(AccessibilityEngine.checkUpId(widget.pages.tongchengyemian.shipinxiaoxin) == ISTRUE) {
            break;
        }else {
            AccessibilityEngine.sleepEngine(1000);//等待
        }
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickIdIndex(widget.pages.tongchengyemian.shipinxiaoxin, 2);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/cb0") == ISTRUE) {
        AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/cb0");
        AccessibilityEngine.sleepEngine(2000);//等待
        AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/c_x");
        AccessibilityEngine.mockOnClickIdIndex(widget.pages.tongchengyemian.shipinxiaoxin,1);
    }
    AccessibilityEngine.sleepEngine(2000);//等待	
	
    if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/cb0") == ISTRUE) {
        showLog("显示执行成功");
        setTaskState("5", "进入直播间请重发一次");

    } else {
      
	    for (var i =0 ; i <search; i ++ ){  //滑动
        if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
        }
       AccessibilityEngine.sleepEngine(5000);//等待
	   
       if( jixing == 1 ){
           var pressjixing = "press," + parseX(660) + "," + parseY(763);
           ScreenEngine.currency(pressjixing);
       } else if( jixing == 2 ){
           ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); 
       }

       if (AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE){
		   if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
			}
           AccessibilityEngine.mockOnClickId(widget.pages.shouye.pinglunKuang); // 点击评论
           AccessibilityEngine.sleepEngine(5000);//等待
           var search2 = contentArr[Math.floor(Math.random()*contentArr.length)];
           AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang, search2); //赋值
           AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
           if (AccessibilityEngine.getEditText(widget.pages.shouye.pinglunKuang)==search2){
               AccessibilityEngine.mockBack();
           }
           if (AccessibilityEngine.getEditText(widget.pages.shouye.pinglunKuang)==search2){
               AccessibilityEngine.mockBack();
           }
           AccessibilityEngine.sleepEngine(1000);//等待
           if ( AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE){
               showLog("点击返回");
               AccessibilityEngine.mockBack();
           }
           if ( AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE){
               showLog("点击返回");
               AccessibilityEngine.mockBack();
           }
       }
       if (i>=search-1){
           showLog("执行成功");
           setTaskState("5", "脚本执行完毕");
           throw SyntaxError();
       }
        AccessibilityEngine.sleepEngine(2000);//等待
        showLog("滑动");
        ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 1500); //从下往上滑动
		
    }
	  
	 
	  
	  
	  
        showLog("执行成功");
        setTaskState("5", "脚本执行完毕");
        throw SyntaxError();
    }
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();